/**
 * \file
 *           tlmRmtCfgDataInfoReqPara.cpp
 * \brief
 *           Implements tlmRmtCfgDataInfoReqPara class for Telematics services
 *           this is the class of ReqPara data infomation of remote configuration.
 *
 * \par Author (last changes):
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Project Leader:
 *          -
 * \par Responsible Developer:
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Architect:
 *          - Zhang Fa
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 *
 * \par Project:
 *      DPCA2
 *
 * \par SW-Component:
 *      Telematics
 *
 * \par SW-Package:
 *      Telematics
 *
 * \par SW-Module:
 *      Telematics Application
 *
* \par SW-Architecture Specification:
 *      DPCA2_TELEMATICS_SW_DD_07a_ready.doc
 *
* \par SW-Design Specification:
 *      DPCA2_TLM-RMTCFG_SW_DD_01d_released.doc
 *
 * \par SW-Test Case Specification:
 *
 * \par CM-Info:
 *
 * \note
 *      This is a note.
 *
 * \bug
 *      - there are no known bugs
 *
 * \par Module-History:
 *
 * \verbatim
 * Date                Author					Reason
 * 10 Dec 2013        Zeng Jie              Initial Creation
 * The latest entry at the head of the history list.
 * \endverbatim
 *
 * \par Copyright Notice:
 * Copyright (C) 2012 Continental Automotive Holdings Co., Ltd.
 * Alle Rechte vorbehalten. All Rights Reserved.\n
 * The reproduction, transmission or use of this document or its contents is
 * not permitted without express written authority.\n
 * Offenders will be liable for damages. All rights, including rights created
 * by patent grant or registration of a utility model or design, are reserved.
 *
 */

#include "stdafx.h"
#include "tlmRmtCfgDataInfoReqPara.h"
#include "teleLogTrace.h"


/**
* \brief tlmRmtCfgDataInfoReqPara: this is constructor of tlmRmtCfgDataInfoReqPara class
*
* \note
*
* \param[in]
* - bufptr: pointer to buffer that store the datainfo message
*   size  : size of the datainfo buffer
*
* \return
* - none
*/
tlmRmtCfgDataInfoReqPara::tlmRmtCfgDataInfoReqPara(uint8_t* bufPtr, uint32_t size) : tlmRmtCfgDataInfo(bufPtr, size){
    //#[ operation tlmRmtCfgDataInfoReqPara(uint8_t*,uint32_t)
    //#]
}

/**
* \brief tlmRmtCfgDataInfoReqPara: this is default constructor of tlmRmtCfgDataInfoReqPara class
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgDataInfoReqPara::tlmRmtCfgDataInfoReqPara() {
}

/**
* \brief ~tlmRmtCfgDataInfoReqPara: this is destructor of tlmRmtCfgDataInfoReqPara class 
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmRmtCfgDataInfoReqPara::~tlmRmtCfgDataInfoReqPara() {
}


/**
* \brief ParseInit:This function is used to parse the dataiofo section of reqpara(28) message. 
*
* \note
*
* \param[in]
* - none
*
* \return
* - bool_t : true - parse the data info message successfully.
*          false - parse the data info message failde
*
* [Covers: MRN_TLM-RMTCFG_SW_DD_037]
*/
bool_t tlmRmtCfgDataInfoReqPara::ParseInit() {
    //#[ operation ParseInit()
    //0x04:web
    //0x05:navi
    //0x08:admin
    //The format for data info of send configuration request message is like below:
    //0x10 0x04 0x05 0x08
    //~~~~ ~~~~ ~~~~ ~~~~
    //  0   1    2    3        
    //  byte 0: Element code, here means list of service ID
    //  byte 1-3: service ID, may not exist if not requested.
    
    bool_t retVal = true;
    uint8_t value;

    LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TLM_MSGSRV]: <tlmRmtCfgDataInfoReqPara::ParseInit> \r\n");
    
    //get first byte, it should be sep "7E"
    mDataInfoBuffer.getValue(value);
    if(value != SEPERATE_LEVEL_1)
    {
        retVal = false;
        LOG_PRINT(DPCA_TELE_MAIN_ERROR,"[TLM_MSGSRV]:<tlmRmtCfgDataInfoReqPara::%s>get invalid seperator [0x%x], should be 0x7E\n", __FUNCTION__, value);
    }
    
    if(retVal)
    {
        //followed should be element code "0x10"
        mDataInfoBuffer.getValue(value);
        if(TLM_RMT_CFG_DATA_INFO_CODE_REQ_SRV_ID_LIST != value)
        {
            retVal = false;
            LOG_PRINT(DPCA_TELE_MAIN_ERROR,"[TLM_MSGSRV]:<tlmRmtCfgDataInfoReqPara::%s>get invalid element code [0x%x]\n", __FUNCTION__, value);
        }
    }
    
    if(retVal)
    {
        //first clear the serviceid list
    
        while(mDataInfoBuffer.getValue(value))
        {
            switch(value)
            {
                case TLM_RMT_CFG_SERVICE_ID_WEB:
                {
                    mParaWeb.SetRequested();
                    LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TLM_MSGSRV]: <tlmRmtCfgDataInfoReqPara::ParseInit> shall send web parameters \r\n");
                    break;
                }
                case TLM_RMT_CFG_SERVICE_ID_NAVI:
                {
                    mParaNavi.SetRequested();
                    LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TLM_MSGSRV]: <tlmRmtCfgDataInfoReqPara::ParseInit> shall send NAVI parameters[%x] \r\n", &mParaNavi);
                    break;
                }
                case TLM_RMT_CFG_SERVICE_ID_ADMIN:
                {
                    mParaAdmin.SetRequested();
                    LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TLM_MSGSRV]: <tlmRmtCfgDataInfoReqPara::ParseInit> shall send ADMIN parameters \r\n");
                    break;
                }
                default:
                {
                    LOG_PRINT(DPCA_TELE_MAIN_ERROR,"[TLM_MSGSRV]:<tlmRmtCfgDataInfoReqPara::%s>get invalid service ID [0x%x]\n", __FUNCTION__, value);
                    break;
                }
            }
        }
    }  
    
    return retVal;
    //#]
}
